﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace PacoToolKit.Format
{
    /// <summary>
    /// 验证工具
    /// </summary>
    public class Validator
    {
        /// <summary>
        /// 是否是数字
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static bool IsNumeric(string value)
        {
            if (string.IsNullOrEmpty(value.Trim()))
                return false;
            else
                return Regex.IsMatch(value, @"^[+-]?\d*[.]?\d*$");
        }

        /// <summary>
        /// 判断是否是日期
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static bool IsDate(string value)
        {
            bool result = true;
            try
            {
                DateTime.Parse(value);
            }
            catch
            {
                result = false;
            }
            return result;
        }

        /// <summary>
        /// 验证
        /// </summary>
        /// <param name="_str">被验证数据</param>
        /// <param name="_alidItem">正则表达式</param>
        /// <returns></returns>
        public static bool IsValidString(string _str, string _validItem)
        {
            return Regex.IsMatch(_str, _validItem);
        }

    }
}
